package com.isunland.managesystem.ui;

import android.util.Log;
import android.widget.Toast;
import com.google.gson.Gson;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.CustomerRelationKeyDepartment;
import com.isunland.managesystem.utils.SharedPreferencesUtil;
import java.util.ArrayList;
import java.util.HashMap;

public class CustomerRelationSuperDepartmentDialogFragment extends BaseNetworkDialogFragment {
  protected static final String TAG =
      CustomerRelationSuperDepartmentDialogFragment.class.getSimpleName();

  //private   DepartMentList mDepartMentList = ;
  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    try {

      CustomerRelationKeyDepartment messageDialogs =
          new Gson().fromJson(arg0, CustomerRelationKeyDepartment.class);
      if (messageDialogs == null || messageDialogs.getDataList() == null) {

        return null;
      }
      for (int i = 0; i < messageDialogs.getDataList().size(); i++) {
        list.add(new CustomerDialog(messageDialogs.getDataList().get(i).getOrgName(),
            messageDialogs.getDataList().get(i).getId()));
      }
      return list;
    } catch (Exception e) {

    }

    return list;
  }

  @Override public String getUrl() {

    return ApiConst.URL_CUSTOMER_RELATION_DEPARTMENT;
  }

  @Override protected void emptyToast() {
    Toast.makeText(getActivity(), R.string.notSuperDep, Toast.LENGTH_SHORT).show();
  }

  @Override public HashMap<String, String> getparameters() {

    HashMap<String, String> params = new HashMap<String, String>();
    params.put("curPage", "1");
    params.put("pageSize", "1000");
    //	String orgName = mDepartMentList.getOrgName().toString();
    String customerId =
        SharedPreferencesUtil.getString(getActivity(), SharedPreferencesUtil.CUSTOMER_ID, "");
    Log.i(TAG, "customerId=" + customerId);
    params.put("customerId", customerId);
    return params;
  }
}
